package work.base.data.string;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;

/**
 * @author shenminglong@kedacom.com
 * @date 2022-01-22
 */
public class StringTest03 {

    public String a = "abc";
    public String b = new String("abc");


    public static void main(String[] args) {

        String string_aaa ="王浩wanghao_sjz";
        System.out.println(string_aaa.replaceAll("[^\\u4e00-\\u9fa5]", ""));//将非中文替换成空

        String aaa = "(项目缺陷验证达标率排名（验证达标率小于100%）";
        String res = aaa.substring(0,aaa.indexOf("排名")+2);
        System.out.println(res);

        String str1 = "(0/1)";
        String res1 = str1.replaceAll("\\(","").replaceAll("\\)","");
        System.out.println(res1);

        String collectedEnd = DateUtil.beginOfDay(DateUtil.date()).offset(DateField.SECOND, -1).toString();

        System.out.println(collectedEnd);
        LocalDate date1 = LocalDate.parse("2021-12-01").with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));

        StringTest03 t = new StringTest03();

        System.out.println(t.a == t.b);

        StringTest03 stringTest03 = new StringTest03();
        String dep = stringTest03.getDepName("AAA/BBB/CCC/DDD/EEE/FFF");

        String name1 = StrUtil.format("你好啊{}","AAA");


        BigDecimal a1 = new BigDecimal(6);
        BigDecimal a2 = new BigDecimal(3);
        BigDecimal r = a2.divide(a1, 4, BigDecimal.ROUND_HALF_UP);
        DecimalFormat decimalFormat = new DecimalFormat("0.00%");
        System.out.println(decimalFormat.format(r));
        System.out.println("END");


    }

    public String getDepName(String dep) {
        if(StrUtil.isEmpty(dep)) {
            return StrUtil.EMPTY;
        } else {
            String[] arr = dep.split("/");
            if(arr.length == 1) {
                return arr[0];
            } else {
                return arr[arr.length-1];
            }
        }
    }
}
